home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / missile.c < prev    next >
C/C++ Source or Header  |  2000-04-16  |  5KB  |  185 lines

  1. /***************************************************************************
  2.  
  3.   vmissile.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. unsigned char *missile_videoram;
  13. int missile_flipscreen;
  14. static int screen_flipped;
  15.  
  16.  
  17. /***************************************************************************
  18.  
  19.   Start the video hardware emulation.
  20.  
  21. ***************************************************************************/
  22. int missile_vh_start(void)
  23. {
  24.  
  25.     /* force video ram to be $0000-$FFFF even though only $1900-$FFFF is used */
  26.     if ((missile_videoram = malloc (256 * 256)) == 0)
  27.         return 1;
  28.  
  29.     memset (missile_videoram, 0, 256 * 256);
  30.     missile_flipscreen = 0x40;
  31.     return 0;
  32. }
  33.  
  34.  
  35.  
  36. /***************************************************************************
  37.  
  38.   Stop the video hardware emulation.
  39.  
  40. ***************************************************************************/
  41. void missile_vh_stop(void)
  42. {
  43.     free (missile_videoram);
  44. }
  45.  
  46. /********************************************************************************************/
  47. int missile_video_r (int address)
  48. {
  49.     return (missile_videoram[address] & 0xe0);
  50. }
  51.  
  52. /********************************************************************************************/
  53. /* This routine is called when the flipscreen bit changes. It forces a redraw of the entire bitmap. */
  54. void missile_flip_screen (void)
  55. {
  56.     screen_flipped = 1;
  57. }
  58.  
  59. /********************************************************************************************/
  60. void missile_blit_w (int offset)
  61. {
  62.     int x, y;
  63.     int bottom;
  64.     int color;
  65.  
  66.     /* The top 25 lines ($0000 -> $18ff) aren't used or drawn */
  67.     y = (offset >> 8) - 25;
  68.     x = offset & 0xff;
  69.     if( y < 231 - 32)
  70.         bottom = 1;
  71.     else
  72.         bottom = 0;
  73.  
  74.     /* cocktail mode */
  75.     if (missile_flipscreen)
  76.     {
  77.         y = Machine->scrbitmap->height - 1 - y;
  78.     }
  79.  
  80.     color = (missile_videoram[offset] >> 5);
  81.  
  82.     if (bottom) color &= 0x06;
  83.  
  84.     plot_pixel(Machine->scrbitmap, x, y, Machine->pens[color]);
  85. }
  86.  
  87. /********************************************************************************************/
  88. void missile_video_w (int address,int data)
  89. {
  90.     /* $0640 - $4fff */
  91.     int wbyte, wbit;
  92.     unsigned char *RAM = memory_region(REGION_CPU1);
  93.  
  94.  
  95.     if (address < 0xf800)
  96.     {
  97.         missile_videoram[address] = data;
  98.         missile_blit_w (address);
  99.     }
  100.     else
  101.     {
  102.         missile_videoram[address] = (missile_videoram[address] & 0x20) | data;
  103.         missile_blit_w (address);
  104.         wbyte = ((address - 0xf800) >> 2) & 0xfffe;
  105.         wbit = (address - 0xf800) % 8;
  106.         if(data & 0x20)
  107.             RAM[0x401 + wbyte] |= (1 << wbit);
  108.         else
  109.             RAM[0x401 + wbyte] &= ((1 << wbit) ^ 0xff);
  110.     }
  111. }
  112.  
  113. WRITE_HANDLER( missile_video2_w )
  114. {
  115.     /* $5000 - $ffff */
  116.     offset += 0x5000;
  117.     missile_video_w (offset, data);
  118. }
  119.  
  120. /********************************************************************************************/
  121. void missile_video_mult_w (int address, int data)
  122. {
  123.     /*
  124.         $1900 - $3fff
  125.  
  126.         2-bit color writes in 4-byte blocks.
  127.         The 2 color bits are in x000x000.
  128.  
  129.         Note that the address range is smaller because 1 byte covers 4 screen pixels.
  130.     */
  131.  
  132.     data = (data & 0x80) + ((data & 8) << 3);
  133.     address = address << 2;
  134.  
  135.     /* If this is the bottom 8 lines of the screen, set the 3rd color bit */
  136.     if (address >= 0xf800) data |= 0x20;
  137.  
  138.     missile_videoram[address]     = data;
  139.     missile_videoram[address + 1] = data;
  140.     missile_videoram[address + 2] = data;
  141.     missile_videoram[address + 3] = data;
  142.  
  143.     missile_blit_w (address);
  144.     missile_blit_w (address + 1);
  145.     missile_blit_w (address + 2);
  146.     missile_blit_w (address + 3);
  147. }
  148.  
  149.  
  150. /********************************************************************************************/
  151. WRITE_HANDLER( missile_video_3rd_bit_w )
  152. {
  153.     int i;
  154.     unsigned char *RAM = memory_region(REGION_CPU1);
  155.     int address = offset + 0x400;
  156.  
  157.     /* This is needed to make the scrolling text work properly */
  158.     RAM[address] = data;
  159.  
  160.     address = ((address - 0x401) << 2) + 0xf800;
  161.     for (i=0; i<8; i++)
  162.     {
  163.         if (data & (1 << i))
  164.             missile_videoram[address + i] |= 0x20;
  165.         else
  166.             missile_videoram[address + i] &= 0xc0;
  167.         missile_blit_w (address + i);
  168.     }
  169. }
  170.  
  171.  
  172. /********************************************************************************************/
  173. void missile_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  174. {
  175.     int address;
  176.  
  177.     if (palette_recalc() || full_refresh || screen_flipped)
  178.     {
  179.         for (address = 0x1900; address <= 0xffff; address++)
  180.             missile_blit_w (address);
  181.  
  182.         screen_flipped = 0;
  183.     }
  184. }
  185.